package lu.med.praxiswahl.wahlumed.dao.beans;

import java.util.List;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.OPSettlementDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.OPSettlementTBL;

/**
 * Session Bean implementation class OPSettlementDAO
 */
@Stateless
@Local(
{ OPSettlementDAOInt.class })
public class OPSettlementDAO implements OPSettlementDAOInt
{

    @PersistenceContext(unitName = "gynaekomedic-ejbPU")
    private EntityManager em = null;

    /**
     * Default constructor.
     */
    public OPSettlementDAO()
    {
	// TODO Auto-generated constructor stub
    }

    @Override
    public void delete(String to_delete)
    {
	OPSettlementTBL op_settlement = em.find(OPSettlementTBL.class,
		to_delete);
	em.remove(op_settlement);
	em.flush();

    }

    @SuppressWarnings("unchecked")
    @Override
    public List<OPSettlementTBL> getAvailableOPSettlementCode()
	    throws RuntimeException
    {
	Query query = em.createNamedQuery("getAvailableOPSettlementCode");

	return (List<OPSettlementTBL>) query.getResultList();
    }

    @Override
    public void persist(OPSettlementTBL to_persist)
    {
	em.persist(to_persist);
	em.flush();

    }

    @Override
    public OPSettlementTBL retrieveOPSettlementCodeByID(String label)
    {
	return (OPSettlementTBL) em.find(OPSettlementTBL.class, label);
    }

    @Override
    public void update(OPSettlementTBL to_update)
    {
	em.merge(to_update);
	em.flush();

    }

    @SuppressWarnings("unchecked")
    @Override
    public List<OPSettlementTBL> getAvailableOPSettlementCodeByClass(
	    int settlementClass) throws RuntimeException
    {
	/*Query query = em
		.createNamedQuery("getAvailableOPSettlementCodeByClass");
	query.setParameter("class", settlementClass);
	return (List<OPSettlementTBL>) query.getResultList();*/
	return null;
    }

}
